/*
 * Course:    CS 590 Web Services
 * Semseter:  Spring 2009
 * Professor: Sedlemeyer
 * Project:   CHEAT (Code Help Educational Assignment Tool)
 * Due Date:  May 1, 2009
 * Team:      Sarcasm
 *            (Baker, Jason; Mitchell, Robin; Shie, Keith)
 */

package cheat.entities;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Holds the core metadata properties associated with the assignment.
 *
 * @author Keith Shie
 */
@Entity
@Table(name = "asgn_prop")
@NamedQueries({@NamedQuery(name = "AssignmentProperty.findAll", query = "SELECT a FROM AssignmentProperty a"),
        @NamedQuery(name = "AssignmentProperty.findByUuid", query = "SELECT a FROM AssignmentProperty a WHERE a.uuid = :uuid"),
        @NamedQuery(name = "AssignmentProperty.findByVersion", query =
        "SELECT a FROM AssignmentProperty a WHERE a.version = :version"),
        @NamedQuery(name = "AssignmentProperty.findByCreateDt", query = "SELECT a FROM AssignmentProperty a WHERE a.createDt = :createDt"),
        @NamedQuery(name = "AssignmentProperty.findByUpdDt", query = "SELECT a FROM AssignmentProperty a WHERE a.updDt = :updDt"),
        @NamedQuery(name = "AssignmentProperty.findByBuildCommand", query = "SELECT a FROM AssignmentProperty a WHERE a.buildCommand = :buildCommand"),
        @NamedQuery(name = "AssignmentProperty.findByTestCommand", query = "SELECT a FROM AssignmentProperty a WHERE a.testCommand = :testCommand"),
        @NamedQuery(name = "AssignmentProperty.findByEstDifficulty", query =
        "SELECT a FROM AssignmentProperty a WHERE a.estDifficulty = :estDifficulty"),
        @NamedQuery(name = "AssignmentProperty.findByEstTime", query = "SELECT a FROM AssignmentProperty a WHERE a.estTime = :estTime"),
        @NamedQuery(name = "AssignmentProperty.findByEstSize", query = "SELECT a FROM AssignmentProperty a WHERE a.estSize = :estSize"),
        @NamedQuery(name = "AssignmentProperty.findByTitle", query = "SELECT a FROM AssignmentProperty a WHERE a.title = :title"),
        @NamedQuery(name = "AssignmentProperty.findByAbstractTxt", query = "SELECT a FROM AssignmentProperty a WHERE a.abstractTxt = :abstractTxt"),
        @NamedQuery(name = "AssignmentProperty.findByCopyright", query = "SELECT a FROM AssignmentProperty a WHERE a.copyright = :copyright"),
        @NamedQuery(name = "AssignmentProperty.findByLearningObjective", query = "SELECT a FROM AssignmentProperty a WHERE a.learningObjective = :learningObjective")})
public class AssignmentProperty implements Serializable {
  private static final long serialVersionUID = 1L;

  @Id
  @Column(name = "uuid", nullable = false )
  @SequenceGenerator(name="assignment_seq", sequenceName="asgn_prop_uuid_seq", allocationSize=1)
  @GeneratedValue( strategy=GenerationType.SEQUENCE,generator="assignment_seq")
  private int uuid;

  @Basic(optional = false)
  @Column(name = "deleted", nullable = false)
  private boolean deleted;

  @Basic(optional = false)
  @Column(name = "version", nullable = false)
  private int version;

  @Basic(optional = false)
  @Column(name = "create_dt", nullable = false)
  @Temporal(TemporalType.TIMESTAMP)
  private Date createDt;
  @Basic(optional = false)
  @Column(name = "upd_dt", nullable = false)
  @Temporal(TemporalType.TIMESTAMP)
  private Date updDt;
  @Column(name = "buildcmd", length = 120)
  private String buildCommand;
  @Column(name = "testcmd", length = 120)
  private String testCommand;
  @Column(name = "est_difficulty")
  private Short estDifficulty;
  @Column(name = "est_time", length = 20)
  private String estTime;
  @Column(name = "est_size")
  private Integer estSize;
  @Column(name = "title", length = 50)
  private String title;
  @Lob
  @Column(name = "abstract")
  private String abstractTxt;
  @Column(name = "copyright", length = 256)
  private String copyright;
  @Column(name = "lrn_objct", length = 256)
  private String learningObjective;
  @Column(name = "chg_descr")
  @Lob
  private String changeDescription;
  @JoinTable(name = "asgn_lang_prop", joinColumns = {@JoinColumn(name = "uuid", referencedColumnName = "uuid", nullable =
          false)},
          inverseJoinColumns = {@JoinColumn(name =
          "lang_cd", referencedColumnName = "lang_cd", nullable = false)})
  @ManyToMany
  private Collection<IsoLanguage> isoLangCollection;
  @JoinTable(name = "asgn_prereq", joinColumns = {@JoinColumn(name = "uuid", referencedColumnName = "uuid", nullable =
          false)}, inverseJoinColumns = {@JoinColumn(name =
          "prereq_uuid", referencedColumnName = "uuid", nullable = false)})
  @ManyToMany
  private Collection<AssignmentProperty> prerequisiteCollection;
  @OneToMany(mappedBy = "parent",fetch=FetchType.LAZY)
  private List<AssignmentProperty> parentList;
  @JoinColumn(name = "parent_uuid", referencedColumnName = "uuid")
  @ManyToOne(fetch=FetchType.LAZY)
  private AssignmentProperty parent;
  @OneToMany(mappedBy = "root",fetch=FetchType.LAZY)
  private List<AssignmentProperty> rootList;
  @JoinColumn(name = "root_uuid", referencedColumnName = "uuid")
  @ManyToOne(fetch=FetchType.LAZY)
  private AssignmentProperty root;
  @ManyToMany(mappedBy = "prerequisiteCollection")
  private Collection<AssignmentProperty> asgnPropCollection1;
  @JoinTable(name = "authormbr", joinColumns = {@JoinColumn(name = "uuid", referencedColumnName = "uuid", nullable =
          false)}, inverseJoinColumns = {@JoinColumn(name =
          "person_id", referencedColumnName = "person_id", nullable = false)})
  @ManyToMany
  private Collection<Person> personCollection;
  @JoinTable(name = "asgn_intd_course", joinColumns = {@JoinColumn(name = "uuid", referencedColumnName = "uuid", nullable =
          false)}, inverseJoinColumns = {@JoinColumn(name = "course_id", referencedColumnName = "course_id", nullable =
          false)})
  @ManyToMany
  private Collection<Course> courseCollection;
  @OneToMany(cascade = CascadeType.ALL, mappedBy = "assignmentProperty")
  private Collection<AssignmentAcl> asgnAclCollection;
  @OneToMany(cascade = CascadeType.ALL, mappedBy = "assignmentProperty")
  private Collection<AssignmentCustomProperty> asgnCustPropCollection;
  @OneToOne(cascade = CascadeType.ALL, mappedBy = "assignmentProperty",fetch=FetchType.LAZY)
  private AssignmentArchive assignmentArchive;
  @OneToOne(cascade = CascadeType.ALL, mappedBy = "assignmentProperty", fetch=FetchType.LAZY)
  private ProgramLanguageSpec progLangSpec;
  @OneToMany(cascade = CascadeType.ALL, mappedBy = "assignmentProperty")
  private Collection<AssignmentCitation> asgnCitationCollection;
  @JoinColumn(name = "asgn_typ_code", referencedColumnName = "asgn_typ_code", nullable = true)
  @ManyToOne(optional = false, fetch=FetchType.LAZY)
  private AssignmentType assignmentTypeCode;
  @JoinColumn(name = "pri_lang_cd", referencedColumnName = "lang_cd", nullable = false)
  @ManyToOne(optional = false, fetch=FetchType.LAZY)
  private IsoLanguage primaryLanguageCode;
  @JoinColumn(name = "license_id", referencedColumnName = "license_id", nullable = false)
  @ManyToOne(optional = false, fetch=FetchType.LAZY)
  private License licenseId;
  @JoinColumn(name = "owner_id", referencedColumnName = "user_id", nullable = false)
  @ManyToOne(optional = false, fetch=FetchType.LAZY)
  private RegisteredUser ownerId;
  @OneToMany(cascade = CascadeType.ALL, mappedBy = "assignmentProperty")
  private Collection<AssignmentExternalUrl> asgnExtUrlCollection;
  @OneToMany(cascade = CascadeType.ALL, mappedBy = "assignmentProperty")
  private Collection<AssignmentKeyword> keywordCollection;

  public AssignmentProperty() {
  }

  public AssignmentProperty(int uuid, int version, Date createDt, Date updDt) {
    this( uuid, version);
    this.createDt = createDt;
    this.updDt = updDt;
  }

  public AssignmentProperty(int uuid, int version) {
    this.uuid = uuid;
    this.version = version;
  }

  public int getUuid() {
    return uuid;
  }

  public void setUuid(int uuid) {
    this.uuid = uuid;
  }


  public boolean isDeleted() {
    return deleted;
  }


  public void setDeleted( boolean deleted ) {
    this.deleted = deleted;
  }

  public int getVersion() {
    return version;
  }

  public void setVersion(int version) {
    this.version = version;
  }

  public Date getCreateDt() {
    return createDt;
  }

  public void setCreateDt(Date createDt) {
    this.createDt = createDt;
  }

  public Date getUpdDt() {
    return updDt;
  }

  public void setUpdDt(Date updDt) {
    this.updDt = updDt;
  }

  public String getBuildCommand() {
    return buildCommand;
  }

  public void setBuildCommand(String buildcmd) {
    this.buildCommand = buildcmd;
  }

  public String getTestCommand() {
    return testCommand;
  }

  public void setTestCommand(String testcmd) {
    this.testCommand = testcmd;
  }

  public Short getEstDifficulty() {
    return estDifficulty;
  }

  public void setEstDifficulty(Short estDifficulty) {
    this.estDifficulty = estDifficulty;
  }

  public String getEstTime() {
    return estTime;
  }

  public void setEstTime(String estTime) {
    this.estTime = estTime;
  }

  public Integer getEstSize() {
    return estSize;
  }

  public void setEstSize(Integer estSize) {
    this.estSize = estSize;
  }

  public String getTitle() {
    return title;
  }

  public void setTitle(String title) {
    this.title = title;
  }

  public String getAbstractTxt() {
    return abstractTxt;
  }

  public void setAbstractTxt(String abstractTxt) {
    this.abstractTxt = abstractTxt;
  }

  public String getCopyright() {
    return copyright;
  }

  public void setCopyright(String copyright) {
    this.copyright = copyright;
  }

  public String getLearningObjective() {
    return learningObjective;
  }

  public void setLearningObjective(String learningObjective) {
    this.learningObjective = learningObjective;
  }

  public Collection<IsoLanguage> getIsoLangCollection() {
    return isoLangCollection;
  }

  public void setIsoLangCollection(Collection<IsoLanguage> isoLangCollection) {
    this.isoLangCollection = isoLangCollection;
  }

  public Collection<AssignmentProperty> getPrerequisiteCollection() {
    return prerequisiteCollection;
  }

  public void setPrerequisiteCollection(Collection<AssignmentProperty> prerequisiteCollection) {
    this.prerequisiteCollection = prerequisiteCollection;
  }

  public Collection<AssignmentProperty> getAsgnPropCollection1() {
    return asgnPropCollection1;
  }

  public void setAsgnPropCollection1(Collection<AssignmentProperty> asgnPropCollection1) {
    this.asgnPropCollection1 = asgnPropCollection1;
  }

  public Collection<Person> getPersonCollection() {
    return personCollection;
  }

  public void setPersonCollection(Collection<Person> personCollection) {
    this.personCollection = personCollection;
  }


  public Collection<Course> getCourseCollection() {
    return courseCollection;
  }


  public void setCourseCollection( Collection<Course> courseCollection ) {
    this.courseCollection = courseCollection;
  }

  public Collection<AssignmentAcl> getAsgnAclCollection() {
    return asgnAclCollection;
  }

  public void setAsgnAclCollection(Collection<AssignmentAcl> asgnAclCollection) {
    this.asgnAclCollection = asgnAclCollection;
  }

  public Collection<AssignmentCustomProperty> getAsgnCustPropCollection() {
    return asgnCustPropCollection;
  }

  public void setAsgnCustPropCollection(Collection<AssignmentCustomProperty> asgnCustPropCollection) {
    this.asgnCustPropCollection = asgnCustPropCollection;
  }

  public AssignmentArchive getAssignmentArchive() {
    return assignmentArchive;
  }

  public void setAssignmentArchive(AssignmentArchive assignmentArchive) {
    this.assignmentArchive = assignmentArchive;
  }

  public ProgramLanguageSpec getProgLangSpec() {
    return progLangSpec;
  }

  public void setProgLangSpec(ProgramLanguageSpec progLangSpec) {
    this.progLangSpec = progLangSpec;
  }

  public Collection<AssignmentCitation> getAssignmentCitationCollection() {
    return asgnCitationCollection;
  }

  public void setAssignmentCitationCollection(Collection<AssignmentCitation> asgnCitationCollection) {
    this.asgnCitationCollection = asgnCitationCollection;
  }

  public AssignmentType getAssignmentTypeCode() {
    return assignmentTypeCode;
  }

  public void setAssignmentTypeCode(AssignmentType assignmentTypeCode) {
    this.assignmentTypeCode = assignmentTypeCode;
  }

  public IsoLanguage getPrimaryLanguageCode() {
    return primaryLanguageCode;
  }

  public void setPrimaryLanguageCode(IsoLanguage primaryLanguageCode) {
    this.primaryLanguageCode = primaryLanguageCode;
  }

  public License getLicenseId() {
    return licenseId;
  }

  public void setLicenseId(License licenseId) {
    this.licenseId = licenseId;
  }

  public RegisteredUser getOwnerId() {
    return ownerId;
  }

  public void setOwnerId(RegisteredUser ownerId) {
    this.ownerId = ownerId;
  }

  public String getChangeDescription() {
    return changeDescription;
  }

  public void setChangeDescription(String changeDescription) {
    this.changeDescription = changeDescription;
  }

  public AssignmentProperty getParent() {
    return parent;
  }

  public void setParent(AssignmentProperty parent) {
    this.parent = parent;
  }

  public AssignmentProperty getRoot() {
    return root;
  }

  public void setRoot(AssignmentProperty root) {
    this.root = root;
  }

  public Collection<AssignmentExternalUrl> getAssignmentExternalUrlCollection() {
    return asgnExtUrlCollection;
  }

  public void setAssignmentExternalUrlCollection(Collection<AssignmentExternalUrl> asgnExtUrlCollection) {
    this.asgnExtUrlCollection = asgnExtUrlCollection;
  }

  public Collection<AssignmentKeyword> getKeywordCollection() {
    return keywordCollection;
  }

  public void setKeywordCollection(Collection<AssignmentKeyword> keywordCollection) {
    this.keywordCollection = keywordCollection;
  }

  @Override
  public int hashCode() {
    int hash = 0;
    hash += (int) uuid;
    hash += (int) version;
    return hash;
  }

  @Override
  public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof AssignmentProperty)) {
      return false;
    }
    AssignmentProperty other = (AssignmentProperty) object;
    if (this.uuid != other.uuid) {
      return false;
    }
    if (this.version != other.version) {
      return false;
    }
    return true;
  }

  @Override
  public String toString() {
    return "cheat.entities.AssignmentProperty[uuid=" + uuid + "]";
  }

}
